package org.display.util
{

	import flash.utils.*;
	
	import org.net.*;
	import org.utils.*;
		
	public class ExtendsClass
	{
		public var path:String=""
			public var extendsPath:String=""

		public function ExtendsClass(path:String,extendsPath:String)
		{
			
			this.path=path
				
				this.extendsPath=extendsPath
					
				doClass()
			
			
		}
		
		public function doClass(){
			
			path=path.replace(/View\.as/gis,"")
				
			extendsPath=extendsPath.replace(/View\.as/gis,"")
				
			doModel(path.replace(/\\View\\/gis,"\\model\\")+"Model.as",
				    extendsPath.replace(/\\View\\/gis,"\\model\\")+"Model.as")
			
			doModelProxy(path.replace(/\\View\\/gis,"\\modelProxy\\")+"ModelProxy.as",
				    extendsPath.replace(/\\View\\/gis,"\\modelProxy\\")+"ModelProxy.as")
			
			doView(path+"View.as",extendsPath+"View.as")
			
			doViewProxy(path.replace(/\\View\\/gis,"\\viewProxy\\")+"ViewProxy.as", 
				   extendsPath.replace(/\\View\\/gis,"\\viewProxy\\")+"ViewProxy.as")
		
		}
		
		function doModel(path:String,extendsPath:String){
			
			var res:AbcResponder=new AbcResponder()
			
			res.onResult=function(e,path){
				
				var source:String=e
				
				//置换继承类
				var regstr:String="extends AbcModel"
				
				var newstr:String="extends "+extendsPath.split("\\")[extendsPath.split("\\").length-1].replace(".as","")
				
				source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				//import 
				regstr="//import"
								
				newstr="import "+extendsPath.replace(/.*?(?=org\\)/gis,"").replace(".as","").replace(/\\/gis,".")+"\n"+regstr
				
				if(source.indexOf(newstr)==-1)source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				setTimeout(FileControl.saveFile,100,path,source)
				
			}
			
			new AbcHTTPServices(path,res)
		
		
		}
		
		function doView(path:String,extendsPath:String){
			var res:AbcResponder=new AbcResponder()
			
			res.onResult=function(e,path){
				
				var source:String=e
				
				//置换继承类
				var regstr:String="extends AbcView"
				
				var newstr:String="extends "+extendsPath.split("\\")[extendsPath.split("\\").length-1].replace(".as","")
				
				source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				//import 
				regstr="//import"
				
				newstr="import "+extendsPath.replace(/.*?(?=org\\)/gis,"").replace(".as","").replace(/\\/gis,".")+"\n"+regstr
				
				if(source.indexOf(newstr)==-1)source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				setTimeout(FileControl.saveFile,100,path,source)
				
			}
			
			new AbcHTTPServices(path,res)
		
		
		}
		
		function doModelProxy(path:String,extendsPath:String){
			var res:AbcResponder=new AbcResponder()
			
			res.onResult=function(e,path){
				
				var source:String=e
				
				//置换继承类
				var regstr:String="extends AbcModelProxy"
				
				var newstr:String="extends "+extendsPath.split("\\")[extendsPath.split("\\").length-1].replace(".as","")
				
				if(source.indexOf(newstr)==-1)source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				//import 
				regstr="//import"
				
				newstr="import "+extendsPath.replace(/.*?(?=org\\)/gis,"").replace(".as","").replace(/\\/gis,".")+"\n"+regstr
				
				if(source.indexOf(newstr)==-1)source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				setTimeout(FileControl.saveFile,100,path,source)
				
			}
			
			new AbcHTTPServices(path,res)
		
		
		}
		
		function doViewProxy(path:String,extendsPath:String){
		
			var res:AbcResponder=new AbcResponder()
			
			res.onResult=function(e,path){
				
				var source:String=e
				
				//置换继承类
				var regstr:String="extends AbcViewProxy"
				
				var newstr:String="extends "+extendsPath.split("\\")[extendsPath.split("\\").length-1].replace(".as","")
				
				if(source.indexOf(newstr)==-1)source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				//import 
				regstr="//import"
				
				newstr="import "+extendsPath.replace(/.*?(?=org\\)/gis,"").replace(".as","").replace(/\\/gis,".")+"\n"+regstr
				
				if(source.indexOf(newstr)==-1)source=source.replace(new RegExp(RegControl.transform(regstr),"gis"),newstr)
				
				setTimeout(FileControl.saveFile,100,path,source)
				
			}
			
			new AbcHTTPServices(path,res)
		
		}
		
		
	}
}